﻿using System;
using System.Collections.Generic;

namespace InDepth2Demo.Chapter3
{
    public class ConverterDemo_2
    {
        public static void Call()
        {
            List<int> testInt = new List<int>();
            testInt.Add(1);
            testInt.Add(2);
            testInt.Add(3);
            testInt.Add(4);

            //List<TOutput> ConvertAll<TOutput>(Converter<T,TOutput> conv)

            Converter<int, double> converter = TaskSquareRoot;   //Converter<int, double>委托，输入int，输出double
            List<double> doubles = testInt.ConvertAll<double>(converter);

            foreach (var item in doubles)
            {
                Console.WriteLine(item);
            }

            Array array = doubles.ToArray();
            var list1 = new List<string>(20);
        }

        static double TaskSquareRoot(int x)
        {
            return Math.Sqrt(x);
        }
    }
}
